package cn.com.nes.site.controller.crm.opportunity;

import cn.com.nes.common.web.CommonResult;
import cn.com.nes.mybatis.agent.crm.entity.OpportunityFile;
import cn.com.nes.site.controller.crm.opportunity.vo.DelOpportunityFileVO;
import cn.com.nes.site.controller.crm.opportunity.vo.GetOpportunityFilePageVO;
import cn.com.nes.site.controller.crm.opportunity.vo.SaveOpportunityFileVO;
import cn.com.nes.site.service.crm.opportunity.OpportunityFileService;
import cn.com.nes.site.service.crm.opportunity.dto.OpportunityFileDto;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Api(tags = {"销售管理-商机管理-商机文件"})
@Controller
@RequestMapping("/v2/crm/opportunityFile")
public class OpportunityFileController {

    @Resource
    private OpportunityFileService opportunityFileService;

    @ApiOperation(value = "查询商机文件分页")
    @RequestMapping(value = "getOpportunityFilePage", method = RequestMethod.GET)
    public @ResponseBody CommonResult<OpportunityFileDto> getOpportunityFilePage(@Validated GetOpportunityFilePageVO vo) throws Exception {
        Page<OpportunityFileDto> opportunityFilePage = opportunityFileService.getOpportunityFilePage(vo.convertToBo());
        return CommonResult.page(opportunityFilePage);
    }

    @ApiOperation(value = "保存商机文件")
    @RequestMapping(value = "saveOpportunityFile", method = RequestMethod.POST)
    public @ResponseBody CommonResult<?> saveOpportunityFile(@RequestBody @Validated SaveOpportunityFileVO vo) throws Exception {
        OpportunityFile opportunityFile = opportunityFileService.saveOpportunityFileFunction(vo.convertToBo());
        return CommonResult.data(opportunityFile.getUuid());
    }

    @ApiOperation(value = "删除商机文件")
    @RequestMapping(value = "delOpportunityFile", method = RequestMethod.POST)
    public @ResponseBody CommonResult<?> delOpportunityFile(@RequestBody @Validated DelOpportunityFileVO vo) throws Exception {
        OpportunityFile opportunityFile = opportunityFileService.delOpportunityFile(vo.convertToBo());
        return CommonResult.data(opportunityFile.getUuid());
    }

}
